<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib/tree" prefix="tree"%>


   <script type="text/javascript">
	   var UEDITOR_HOME_URL ="${ctx}/ueditor/"; 
	</script>

 <script type="text/javascript" charset="utf-8" src="${ctx}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx}/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${ctx}/ueditor/lang/zh-cn/zh-cn.js"></script>

    <style type="text/css">
         .td{ width:80px;}
        .tittle{ width:75%;}
    </style>

<form name="addDataForm" id="addContentDataForm" method="post" action="${ctx}/business/webcontent/save">
	<input type="hidden" name="budgetMenuData" id="budgetMenuData" value=""/>
	<input type="hidden" name="projectId" id="projectId" value="${projectId}"/>
	<input type="hidden" name="isDisplay" id="isDisplay" value="0"/><!-- 显示 -->
	
	<table class="infoTable">
		<tbody>
			<tr>
				<th align="right" width="6%">标题</th>
				<td colspan="5">
					<input id="newTitle" name="title" class="easyui-validatebox tittle" data-options="required:true,validType:['isBlank']" size="30" value="${webcontent.title}" data-options="required:true" maxlength="50" />
				</td>
			</tr>
			<tr>
				<th align="right" width="6%">类型</th>
				<td>
					<input id="type" name="type" />
				</td>
			</tr>
			<tr>
				<th align="right" width="6%">内容</th>
				<td colspan="5">
					<script id="editor" name="contentView" type="text/plain" style="width: 100%; height: 500px;">${webcontent.content}</script>
					<input type="hidden" name="content" id="contentMsg" value=""></input>
				</td>
			</tr>
			<tr>
				<th align="right" width="6%">附件</th>
				<td style="border-right: none" width="35%">
					<div id="fileQueue" style="margin: 10px 0px 0px 10px">
						<input type="file" name="uploadify" id="uploadify" class="uploadify" data-options="required:true"/>
						<p style="color: #aaaaaa;width: auto">
							1、按住Ctrl可选择多个文件上传;<br/>
							2、可上传rar,zip,doc,docx,xls,xlsx,jpg,gif,bmp,pdf类型文件<br/>
						</p>
					</div>
				</td>
			</tr>
		</tbody>
	</table>
</form>


<script type="text/javascript">

//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
var ue = UE.getEditor('editor');

bindWebType();
	function getEditorHTMLContents() { 
		var html = ue.getContent();
		return html;
	} 
 
	function selectParentArticle(){
		selarticlePidArticleTree($('#articlePid').val());
		$('#articlePidArticleTreeDialog').dialog('open');
	}
	
	/**获取文章类型**/
	function bindWebType(){
		$('#type').combobox({
             url:'${ctx}/business/webcontent/oppugnTypeList?t='+new Date().getTime(),
                valueField:'id',
                textField:'name',
                onLoadSuccess: function () { //加载完成后,设置选中第一项
	                  var val = $(this).combobox("getData");
		              for(var i=0;i<val.length;i++){
	                	 if (val[i].id == '${webcontent.type}') {
	                	 	 $(this).combobox("select", val[i].id);
	                	 	 break;
	                	 }
		                 $(this).combobox("select", val[0].id);
		              }
	           },
	           filter: function(q, row){
	               var opts = $('#type').combobox('options');
	               return 2;
	           }
        });
	}
	
	function bindArticleType(){
		  $.ajax({
		   url:'${ctx}/business/webtypemanage/listAll?t='+new Date().getTime(),
		   type:'post',
		   success:function(data){
		    var opt='';
		    for(var i=0;i<data.length;i++){
		      if(data[i].id=="1") continue;
		      opt+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
		    }
		     $('select[name=type]').append(opt);
		   },
		   error:function(){
		   
		   }
		  });
		}
	
	
	$(function(){
		/**
		 *附件 /business/projectmanage
		 **/
		$("#uploadify").uploadify({
			'height'        : 27,   
            'width'         : 80,    
            'buttonText'    : '选择附件',
            'queueID': 'fileQueue',//队列的ID
            'queueSizeLimit':5,// 附件附列长度
			'swf': '${ctx}/commons/js/uploadify/uploadify.swf',
			'uploader':'${ctx}/auction/business/upload;jsessionid=${pageContext.session.id}?functionFlag=103',// 上传时请求的后台处理的controller
			'cancelImg': '${ctx}/commons/js/uploadify/uploadify-cancel.png',
			'method':'post',  
			'folder': '',
			'preventCaching' : true,
			'fileTypeExts' :'*.rar;*.zip;*.doc;*.docx;*.xls;*.xlsx;*.jpg;*.gif;*.bmp;*.pdf;*.dwg',
			'auto': true,
			'multi': true,//是否可多选
			'removeCompleted' : false,
			'successTimeout' : 55555,
			'onUploadSuccess':function(file, data, response){
				$('#' + file.id).find('.data').html(' 上传完毕');
				$('#budgetMenuData').val($('#budgetMenuData').val() + "," + data);
				var cancel=$('#fileQueue .uploadify-queue-item[id="' + file.id + '"]').find(".cancel a");
				if (cancel) {
				   cancel.attr("rel", data);
				   cancel.click(function () {
					   var cancelData = cancel.attr("rel");
		               var  budgetMenuData = $('#budgetMenuData').val();
		               var index = budgetMenuData.indexOf(","+cancel.attr("rel"))
		               if(index != -1){
		            	   budgetMenuData = budgetMenuData.replace(","+cancelData,"");
		            	   $('#budgetMenuData').val(budgetMenuData);
		               }
				   });
				}
			},
			'onSelectError':function(file, errorCode, errorMsg){
				switch(errorCode) {
					case -110:
						//this.queueData.errorMsg="文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小！";
						this.queueData.errorMsg='所选文件大小超出系统限制!';
						break;
					case -120:
						//this.queueData.errorMsg="文件 ["+file.name+"] 大小异常！"
						this.queueData.errorMsg='所选文件大小异常!';
						break;
					case -130:
						//this.queueData.errorMsg="文件 ["+file.name+"] 类型不正确！"
						this.queueData.errorMsg='所选文件类型不正确!';
						break;
				}
			},
			'onCancel' : function(file){
				alert(file);
			}
		});
	});

	function deleteFile(v,resId){
		var parent = v.parentNode;
		parent.parentNode.removeChild(parent);
		var  budgetMenuData = $('#budgetMenuData').val();
        var index = budgetMenuData.indexOf(","+resId)
        if(index != -1){
     	   budgetMenuData = budgetMenuData.replace(","+resId,"");
     	   $('#budgetMenuData').val(budgetMenuData);
        }

        //删除数据库中的文件信息
        $.ajax({
			type : "post",
			url : "${ctx}/auction/business/deleteFile?resId="+resId,
			data : top.$("#addProjectsDataForm").serialize(),
			success : function(data){
				
			},
			error : function(data){
				alert("错误");
			}
		});
	}

</script>